package com.wms.controller;

import com.mes.entity.User;
import com.wms.service.SalesoutletService;
import com.yy.base.page.Message;
import com.yy.base.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("Salesoutlet")
public class SalesoutletController {
    @Autowired
    private SalesoutletService salesoutletService;


    //加载工单信息
    @ResponseBody
    @RequestMapping(value = "rfidLists", method = RequestMethod.POST)
    public Message rfidLists(HttpServletRequest request) {
        Message msg = new Message();
        try {
            String rfid = "";
            if (request.getParameter("rfid") != null && request.getParameter("rfid") != "") {
                rfid = request.getParameter("rfid");
            } else {
                msg.setData("results", "false");
                msg.setErrorMessage("[RFID]不能为空！");
                return msg;
            }


            List<Map<String, Object>> zyList = salesoutletService.getjobStatusList(rfid);

            if(zyList.size() > 0){

                msg.setData("rfidLists", salesoutletService.getjobStatusList(rfid));
                String uomid = zyList.get(0).get("DWID") == null ? null : zyList.get(0).get("DWID").toString();

                String jobid = zyList.get(0).get("JOBID") == null ? null : zyList.get(0).get("JOBID").toString();

                String jobcode = zyList.get(0).get("ZYCODE") == null ? null : zyList.get(0).get("ZYCODE").toString();

                String BATCHID = zyList.get(0).get("BATCHID") == null ? null : zyList.get(0).get("BATCHID").toString();

                User user = UserUtil.getUser();
                salesoutletService.inStorageInOut( 1, uomid, jobid, user, jobcode,BATCHID);
                salesoutletService.uodateStatus(jobid);
            } else {
                msg.setData("results", "false");
                msg.setErrorMessage("[" + rfid + "]不存在,或该工单已出库！");
                return msg;
            }


            msg.setData("results", "true");
            msg.setOkMessage("处理成功！");
        } catch (Exception e) {
            msg.setData("results", "false");
            msg.setErrorMessage("处理失败！");
            e.printStackTrace();
        }
        return msg;
    }


}
	
	
	
	
